package com.ruoyi.jobservice.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.manager.domain.SoldierBaseInfo;
import com.ruoyi.manager.domain.SoldierEmploymentInfo;
import com.ruoyi.manager.mapper.SoldierBaseInfoMapper;
import com.ruoyi.manager.mapper.SoldierEmploymentInfoMapper;
import com.ruoyi.manager.service.ISoldierBaseInfoService;
import com.ruoyi.manager.vo.SoldierFullMessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.jobservice.mapper.SSoldierJobInfoMapper;
import com.ruoyi.jobservice.domain.SSoldierJobInfo;
import com.ruoyi.jobservice.service.ISSoldierJobInfoService;

/**
 * 退役军人就业创业信息Service业务层处理
 * 
 * @author jeffery
 * @date 2021-08-31
 */
@Service
public class SSoldierJobInfoServiceImpl implements ISSoldierJobInfoService 
{
    @Autowired
    private SSoldierJobInfoMapper sSoldierJobInfoMapper;

    @Autowired
    private SoldierBaseInfoMapper soldierBaseInfoMapper;
    @Autowired
    private SoldierEmploymentInfoMapper soldierEmploymentInfoMapper;
    @Autowired
    private ISoldierBaseInfoService soldierBaseInfoService;

    /**
     * 查询退役军人就业创业信息
     * 
     * @param id 退役军人就业创业信息主键
     * @return 退役军人就业创业信息
     */
    @Override
    public SSoldierJobInfo selectSSoldierJobInfoById(Long id)
    {
        return sSoldierJobInfoMapper.selectSSoldierJobInfoById(id);
    }

    /**
     * 查询退役军人就业创业信息列表
     * 
     * @param sSoldierJobInfo 退役军人就业创业信息
     * @return 退役军人就业创业信息
     */
    @Override
    public List<SSoldierJobInfo> selectSSoldierJobInfoList(SSoldierJobInfo sSoldierJobInfo)
    {
        return sSoldierJobInfoMapper.selectSSoldierJobInfoList(sSoldierJobInfo);
    }

    /**
     * 新增退役军人就业创业信息
     * 
     * @param sSoldierJobInfo 退役军人就业创业信息
     * @return 结果
     */
    @Override
    public int insertSSoldierJobInfo(SSoldierJobInfo sSoldierJobInfo)
    {
        sSoldierJobInfo.setCreateTime(DateUtils.getNowDate());
        sSoldierJobInfo.setStatus(1);
        return sSoldierJobInfoMapper.insertSSoldierJobInfo(sSoldierJobInfo);
    }

    /**
     * 修改退役军人就业创业信息
     * 
     * @param sSoldierJobInfo 退役军人就业创业信息
     * @return 结果
     */
    @Override
    public int updateSSoldierJobInfo(SSoldierJobInfo sSoldierJobInfo)
    {
        sSoldierJobInfo.setUpdateTime(DateUtils.getNowDate());
        return sSoldierJobInfoMapper.updateSSoldierJobInfo(sSoldierJobInfo);
    }

    /**
     * 批量删除退役军人就业创业信息
     * 
     * @param ids 需要删除的退役军人就业创业信息主键
     * @return 结果
     */
    @Override
    public int deleteSSoldierJobInfoByIds(Long[] ids)
    {
        return sSoldierJobInfoMapper.deleteSSoldierJobInfoByIds(ids);
    }

    /**
     * 删除退役军人就业创业信息信息
     * 
     * @param id 退役军人就业创业信息主键
     * @return 结果
     */
    @Override
    public int deleteSSoldierJobInfoById(Long id)
    {
        return sSoldierJobInfoMapper.deleteSSoldierJobInfoById(id);
    }

    @Override
    public AjaxResult getSoldierMessage(String idNumber) {
        SoldierBaseInfo soldierBaseInfo = soldierBaseInfoMapper.selectOne(new QueryWrapper<SoldierBaseInfo>().lambda().eq(SoldierBaseInfo::getIdNumber, idNumber));
        if (soldierBaseInfo == null){
            return AjaxResult.error("军人身份证号: '" + idNumber + "'验证失败，该身份证号信息不存在");
        }
        soldierBaseInfoService.changeBaseNumToStr(soldierBaseInfo);
        //Long soldierId = soldierBaseInfo.getId();
        //SoldierEmploymentInfo soldierEmploymentInfo = soldierEmploymentInfoMapper.selectOne(new QueryWrapper<SoldierEmploymentInfo>().lambda().eq(SoldierEmploymentInfo::getSoldierId, soldierId));

        SoldierFullMessageVo fullMessageVo = new SoldierFullMessageVo();

        fullMessageVo.setSoldierBaseInfo(soldierBaseInfo);

        //fullMessageVo.setSoldierEmploymentInfo(soldierEmploymentInfo);

        return AjaxResult.success(fullMessageVo);
    }
}
